package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.NewsComment;
import cn.wolfcode.trip.base.domain.StrategyComment;
import cn.wolfcode.trip.base.mapper.NewsCommentMapper;
import cn.wolfcode.trip.base.query.NewsCommentQuery;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.query.StrategyCommentQueryObject;
import cn.wolfcode.trip.base.service.INewsCommentService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class NewsCommentServiceImpl implements INewsCommentService {
    @Autowired
    private NewsCommentMapper commentMapper;

    @Override
    public PageInfo newsComment(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        return new PageInfo(commentMapper.selectForList(qo));
    }

    //查询出所有评论,并且分页
    @Override
    public PageInfo queryForApp(NewsCommentQuery qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<NewsComment> list = commentMapper.queryFoListApp(qo);
        for (NewsComment comment : list) {
            String[] imgUrlsArr = comment.getCoverUrl().split(";");
            comment.setImgUrlsArr(imgUrlsArr);
        }
        return new PageInfo(list);
    }

    //通过攻略id查询出单个指定评论
    @Override
    public NewsComment getNewsCommentById(Long id) {
        NewsComment comment = commentMapper.selectNewsCommentById(id);
        return comment;
    }
}
